package cn.coderliu.controller;

import cn.coderliu.apis.AccountApis;
import cn.coderliu.mapper.ProductMapper;
import com.taobao.txc.common.TxcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/product")
public class ProductController {

    @Autowired
    ProductMapper productMapper;
    @Autowired
    AccountApis accountApis;

    @PostMapping("/add")
    public void add(@RequestParam("count") Integer count) {
        String xid = TxcContext.getCurrentXid();
        System.out.println("事务传递xid为：" + xid);
        productMapper.add(count);
        accountApis.add(count*10);
    }


    @PostMapping("/reduce")
    public void reduce(Integer count) {
        String xid = TxcContext.getCurrentXid();
        System.out.println("事务传递xid为：" + xid);
        productMapper.reduce(count);
        accountApis.reduce(count*10);
    }
}
